package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ParkingAccessKeys;
import com.ruoyi.service.IParkingAccessKeysService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 访问密钥Controller
 * 
 * @author dongdong
 * @date 2025-08-21
 */
@RestController
@RequestMapping("/parking/accessKeys")
public class ParkingAccessKeysController extends BaseController
{
    @Autowired
    private IParkingAccessKeysService parkingAccessKeysService;

    /**
     * 查询访问密钥列表
     */
    @PreAuthorize("@ss.hasPermi('parking:accessKeys:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkingAccessKeys parkingAccessKeys)
    {
        startPage();
        List<ParkingAccessKeys> list = parkingAccessKeysService.selectParkingAccessKeysList(parkingAccessKeys);
        return getDataTable(list);
    }

    /**
     * 导出访问密钥列表
     */
    @PreAuthorize("@ss.hasPermi('parking:accessKeys:export')")
    @Log(title = "访问密钥", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkingAccessKeys parkingAccessKeys)
    {
        List<ParkingAccessKeys> list = parkingAccessKeysService.selectParkingAccessKeysList(parkingAccessKeys);
        ExcelUtil<ParkingAccessKeys> util = new ExcelUtil<ParkingAccessKeys>(ParkingAccessKeys.class);
        util.exportExcel(response, list, "访问密钥数据");
    }

    /**
     * 获取访问密钥详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:accessKeys:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(parkingAccessKeysService.selectParkingAccessKeysById(id));
    }

    /**
     * 创建访问密钥
     */
    @PreAuthorize("@ss.hasPermi('parking:accessKeys:add')")
    @GetMapping(value = "/createAccessKeys")
    public AjaxResult createAccessKeys()
    {
        return success(parkingAccessKeysService.createAccessKeys());
    }

    /**
     * 新增访问密钥
     */
    @PreAuthorize("@ss.hasPermi('parking:accessKeys:add')")
    @Log(title = "访问密钥", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkingAccessKeys parkingAccessKeys)
    {
        return toAjax(parkingAccessKeysService.insertParkingAccessKeys(parkingAccessKeys));
    }

    /**
     * 修改访问密钥
     */
    @PreAuthorize("@ss.hasPermi('parking:accessKeys:edit')")
    @Log(title = "访问密钥", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkingAccessKeys parkingAccessKeys)
    {
        return toAjax(parkingAccessKeysService.updateParkingAccessKeys(parkingAccessKeys));
    }

    /**
     * 删除访问密钥
     */
    @PreAuthorize("@ss.hasPermi('parking:accessKeys:remove')")
    @Log(title = "访问密钥", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(parkingAccessKeysService.deleteParkingAccessKeysByIds(ids));
    }

    @GetMapping("/selectList")
    public AjaxResult selectList() {
        return success(parkingAccessKeysService.selectList());
    }
}
